import React, { Component, Fragment } from 'react';
import { to } from 'await-to-js'
import axios from 'axios'
import anime from 'animejs/lib/anime.es.js';

import './home.css';

class App extends Component {

  state = {
    iosUrl: '',
    androidApkUrl: '',
    iosTFUrl: ''
  }

  componentDidMount = async () => {

    anime({
      targets: this.home_banner,
      scale: [0, 1],
      duration: 800,
      easing: 'easeInOutExpo',
      autoplay: true
    })
    this.getType6();
    this.getType2();
    var [err, { data: response }] = await to(axios.get('https://a1.20app.vip/user/client/version/list?type=1'))
    if (err) return void alert(err.message)
    var { status, msg, data } = response
    if (status != 1) return void alert(msg)

    var { iosUrl, androidApkUrl } = data
    this.setState({
      androidApkUrl
    })
 

  }
  async getType2() {
    var [err, { data: response }] = await to(axios.get('https://a1.20app.vip/user/client/version/list?type=2'))
    if (err) return void alert(err.message)
    var { status, msg, data } = response
    if (status != 1) return void alert(msg)

    var { iosUrl: iosTFUrl } = data
    this.setState({
      iosTFUrl
    })
  }
  async getType6() {
    var [err, { data: response }] = await to(axios.get('https://a1.20app.vip/user/client/version/list?type=6'))
    if (err) return void alert(err.message)
    var { status, msg, data } = response
    if (status != 1) return void alert(msg)
    var { iosUrl } = data
    this.setState({
      iosUrl
    })
  }
  ddlHandler = (url,name) => {
    console.log(url,name);
    
    if(name=='to'){
      return window.location.href=url;
    }
    var link = document.createElement('a');
    link.download = '20';
    link.style.display = 'none';
    link.href = url;
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
  }
  goDownload(){ //企业签下载
    console.log('企业签下载');
    window.location.href = this.state.iosUrl ||'https://www.20.show/front/download/#/'
  }

  render = () => <Fragment>
    <div className="homeBg"></div>
    <div className="home_container">
      <div ref={ref => this.home_banner = ref} className="home_banner"></div>
      <div className="home_title">滚烫的青春/美丽的邂逅</div>
      <div className="home_ddl">
        <div onClick={() => void this.ddlHandler(this.state.androidApkUrl)}>
          <div></div>
          <span>Android下载</span>
        </div>
        <div onClick={() => this.ddlHandler(this.state.iosTFUrl)}>
          <div></div>
          <span>iOS下载</span>
        </div>
        {/* <div onClick={() => void this.ddlHandler(this.state.iosTFUrl,'to')}>
          <div></div>
          <span>iOS下载(TF)</span>
        </div> */}
      </div>
      {/* <div className="home_qrcode"></div> */}
    </div>
  </Fragment>
}

export default App;


